import { ref } from 'vue'
import {getSmsTemplateList, syncSmsTemplate} from '../../../../api/sms'
import { SmsTemplateListItem, getSmsTemplateListParam } from '../types'

// 获取短信模版列表加载状态
const getSmsTemplateListLoading = ref(false)

// 短信模版列表
const smsTemplateList = ref<Array<SmsTemplateListItem>>()

// 短信模版列表总条数
const totalList = ref(0)

// 获取短信模块列表方法
const getSmsTemplatesFn = async (data: getSmsTemplateListParam) => {
    getSmsTemplateListLoading.value = true
    const res = await getSmsTemplateList(data)
    smsTemplateList.value = res.data.data.rows
    getSmsTemplateListLoading.value = false
    totalList.value = res.data.data.total
}

// 同步短信模版加载状态
const syncSmsTemplateLoading = ref(false)

// 同步短信模版方法
const syncSmsTemplateFn = async () => {
    syncSmsTemplateLoading.value = true
    const res = await syncSmsTemplate()
    syncSmsTemplateLoading.value = false
    return res.data
}

export default {
    totalList,
    smsTemplateList,
    syncSmsTemplateLoading,
    getSmsTemplateListLoading,
    getSmsTemplatesFn,
    syncSmsTemplateFn,
}